SQL Views
SQL CREATE VIEW Statement
Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table in the database. We can create a view by selecting fields from one or more tables present in the database.
A View can either have all the rows of a table or specific rows based on certain condition.
CREATE VIEW:
CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name
WHERE condition;
view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows
Example:
CREATE VIEW DetailsView AS SELECT NAME, ADDRESS FROM StudentDetails WHERE S_ID < 5;
DROP VIEW:
DROP VIEW view_name;
view_name: Name of the View which we want to delete.
Inserting a row in a view:
INSERT INTO view_name(column1, column2 , column3,..) VALUES(value1, value2, value3..);
view_name: Name of the View